package com.dyz.leetcode._20_dynamicProgramming._62;

import java.util.Arrays;

public class uniquePaths01 {
    private int m;
    private int n;
    private int[][] memo;
    public int uniquePaths(int m, int n) {
        this.m= m;
        this.n = n;
        memo = new int[m][n];
        for (int i = 0; i <m ; i++) {
            Arrays.fill(memo[i], -1);
        }

        return dfs(0, 0);

    }

    private int dfs(int i, int j){
        if(i==m-1|| j==n-1){return 1;}
        if(i==m||j==n){return 0;}

        if(memo[i][j]!=-1){return memo[i][j];}
        int left = dfs(i+1, j);
        int right = dfs(i, j+1);

        memo[i][j] = left+right;

        return memo[i][j];
    }
}
